<?
include_once('conn.php');
include_once('include/func.php');
include("admin_check.php") ;
if($admin[0][2]<>10){exit('<script>alert("您没有权限"); window.history.back(-1);</script>');}

?>	
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><? echo systemname;?></title>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<link href="css/admin.css" rel="stylesheet" type="text/css" />
	<!-- jquery packed -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="js/dtree.js"></script>
	<!-- tableRowCheckboxToggle -->
    <script type="text/javascript"> 
    function fade() 
{ 
    //停留2秒后消失,在停留的时候,透明度为1.0什么都不做 
    $('<div id="add" class="quick-alert">操作成功</div>').insertAfter($("#example")).animate({opacity: 1.0}, 2000).fadeOut("slow",function(){ 
   //隐藏时把元素删除 
   $(this).remove(); 
}); 
} 
</script> 

<script src="js/jc_table.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="css/xtheme-gray.css" />
    <!-- GC -->
 	<!-- LIBS -->
 	<script type="text/javascript" src="js/ext-base.js"></script>
 	<!-- ENDLIBS -->

    <script type="text/javascript" src="js/ext-all.js"></script>
 

  <?
  $thisy = $_GET[y]==null?date('Y'):$_GET[y];
  $list = $db->select("SELECT express_time,price FROM `".tablepre."order` where paid = 1 and situation = 2");
	  for($i=0;$i<count($list);$i++){ 
	  if(substr($list[$i][0],0,4)==$thisy){

		  $order_total_arr .= substr($list[$i][0],5,2).',';
		  $order_total_arr_price .= '\''.$list[$i][1].'\',';
		  $order_total_arr_pre_m_price .= $list[$i][0].'|'.$list[$i][1].',';
		  }
		  
	  }
	 $order_total_array_price = 'array('.substr($order_total_arr_price,0,-1).');';
	  for($i=1;$i<=12;$i++){
		  $value=substr_count($order_total_arr,$i)==null?0:substr_count($order_total_arr,$i);
		  $row_m .= "{name:'".$i."月', visits: ".$value."},";
		  }
		  $row_m=substr($row_m,0,-1);
		 eval("\$arr_price = ".$order_total_array_price);
		 
		 
		 foreach(explode(',',$order_total_arr_pre_m_price) as $v){
			// echo $v.'##';
			$arr = explode('|',$v);
			for($i=1;$i<=12;$i++){
				if(substr_count(substr($arr[0],5,2),$i)){
					
					$count_a .= '$a'.$i.'[]="'.$arr[1].'";';
					//echo $arr[1].',';
					}
				}
			//echo substr($arr[0],5,2).',';
			//print_r($arr);
			 }
			 eval($count_a);

			 $pre_m_1 = @array_sum($a1)==null?0:array_sum($a1);
			 $pre_m_2 = @array_sum($a2)==null?0:array_sum($a2);
			 $pre_m_3 = @array_sum($a3)==null?0:array_sum($a3);
			 $pre_m_4 = @array_sum($a4)==null?0:array_sum($a4);
			 $pre_m_5 = @array_sum($a5)==null?0:array_sum($a5);
			 $pre_m_6 = @array_sum($a6)==null?0:array_sum($a6);
			 $pre_m_7 = @array_sum($a7)==null?0:array_sum($a7);
			 $pre_m_8 = @array_sum($a8)==null?0:array_sum($a8);
			 $pre_m_9 = @array_sum($a9)==null?0:array_sum($a9);
			 $pre_m_10 = @array_sum($a10)==null?0:array_sum($a10);
			 $pre_m_11 = @array_sum($a11)==null?0:array_sum($a11);
			 $pre_m_12 = @array_sum($a12)==null?0:array_sum($a12);
			 ///////////////
			 $row_pre_m = "{name:'1月', visits: ".$pre_m_1."},{name:'2月', visits: ".$pre_m_2."},{name:'3月', visits: ".$pre_m_3."},{name:'4月', visits: ".$pre_m_4."},{name:'5月', visits: ".$pre_m_5."},{name:'6月', visits: ".$pre_m_6."},{name:'7月', visits: ".$pre_m_7."},{name:'8月', visits: ".$pre_m_8."},{name:'1月', visits: ".$pre_m_9."},{name:'1月', visits: ".$pre_m_9."},{name:'1月', visits: ".$pre_m_10."},{name:'1月', visits: ".$pre_m_10."},{name:'11月', visits: ".$pre_m_11."},{name:'12月', visits: ".$pre_m_12."}";
			 
			$list_item = $db->select("SELECT a.iid FROM `".tablepre."order_item` a left join `".tablepre."order` b on (a.oid = b.oid) where b.paid = 1 and b.situation = 2"); 
			
		  
  ?>
  
  <? //echo $row_m;?>
  <? //echo $pre_m_1.','.$pre_m_2.','.$pre_m_3.','.$pre_m_4.','.$pre_m_5.','.$pre_m_6.','.$pre_m_7.','.$pre_m_8.','.$pre_m_9.','.$pre_m_10.','.$pre_m_11.','.$pre_m_12;?>
  <script class="code" type="text/javascript">
Ext.onReady(function(){

    var store = new Ext.data.JsonStore({
        fields:['name', 'visits', 'views'],
        data: [
            <? echo $row_m;?>
        ]
    });

    // extra extra simple
    new Ext.Panel({
        title: '<? echo $thisy;?>年每月订单量统计[单位：<? echo parameters(24);?>]',
        renderTo: 'premonthordercount',
        width:550,
        height:300,
        layout:'fit',

        items: {
            xtype: 'linechart',
            store: store,
            xField: 'name',
            yField: 'visits',
			listeners: {
				itemclick: function(o){
					var rec = store.getAt(o.index);
					Ext.example.msg('Item Selected', 'You chose {0}.', rec.get('name'));
				}
			}
        }
    });

    var store1 = new Ext.data.JsonStore({
        fields:['name', 'visits', 'views'],
        data: [
            <? echo $row_pre_m;?>
        ]
    });
    new Ext.Panel({
        title: '<? echo $thisy;?>年每月销售额统计[单位：<? echo $unit[0][0];?>]',
        renderTo: 'premonthsalesvolumetotal',
        width:550,
        height:300,
        layout:'fit',

        items: {
            xtype: 'linechart',
            store: store1,
            xField: 'name',
            yField: 'visits',
			listeners: {
				itemclick: function(o){
					var rec = store.getAt(o.index);
					Ext.example.msg('Item Selected', 'You chose {0}.', rec.get('name'));
				}
			}
        }
    });
    // extra simple
 

    // more complex with a custom look
    
});
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
  </script>
</head>
<body <? echo isset($_GET[ok])?'onload="fade();"':''; ?>>
<div id="wrap">
<div id="main" class="clearfix">
<div id="side">
  </div>
  <div id="head"><? include_once('admin_head.php');?></div>
  <div id="left"><?
  include_once('admin_menu.php');
  ?></div>
  <div id="right">


<img src="images/ttfjpg.php?t=销售统计&amp;bg=titlebg2.jpg&amp;z=18&amp;x=5&amp;y=22&amp;r=0&amp;b=0&amp;g=0"  /><br />
<h2>总订单量：<? echo count($list);?>个 | 总销售额：<? echo unit(array_sum($arr_price));?> | 销售总商品数：<? echo count($list_item);?>件</h2><br />
<form name="form" id="form">
  <select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)">
    <option value="">选择年份</option>
    <?
    for($i=date('Y')-20;$i<=date('Y');$i++){
		echo '<option value="?y='.$i.'">'.$i.'</option>';
		}
	?>
  </select>
</form>
只统计成功支付并已发货订单
<div id="premonthordercount" style="margin-bottom:10px;">
</div>
<div id="premonthsalesvolumetotal" style="margin-bottom:10px;">
</div>

<p><br />
<br />
</p>
</div>
  </div>
</div>

<div id="footer">
<?
include_once('fooder.php');
?>
</div>
</BODY>
</HTML>
